/**
 * 
 */
package com.rong.action;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.rong.ORM.ZynCarMaintain;
import com.rong.ORM.ZynUser;
import com.rong.hibernate.Const;
import com.rong.DAO.ZynCarMaintainDAO;

/**
 * @author wafech
 *
 */
public class CarMtAction extends ActionSupport {
	ZynCarMaintain carmt=new ZynCarMaintain();
	ZynCarMaintainDAO carDao=new ZynCarMaintainDAO();
	private List<ZynCarMaintain> list;
	private String saveFlag="";
	private int id=-1; // the car id indatabase.

	private Date startdate;
	private String query_carnum="";
	private int rowsPerPage =25;// 每页显示几条
	private int page = 1; // 默认当前页
	private int totalPage;// 总共多少页
	private int planNum;// 总过多少条
	
	
	    /**
	 * @return the list
	 */
	public List<ZynCarMaintain> getList() {
		return list;
	}

	/**
	 * @param list the list to set
	 */
	public void setList(List<ZynCarMaintain> list) {
		this.list = list;
	}

	
	
	
		/**
	 * @return the carmt
	 */
	public ZynCarMaintain getCarmt() {
		return carmt;
	}

	/**
	 * @param carmt the carmt to set
	 */
	public void setCarmt(ZynCarMaintain carmt) {
		this.carmt = carmt;
	}

		/**
	 * @return the saveFlag
	 */
	public String getSaveFlag() {
		return saveFlag;
	}

	
	/**
		 * @return the id
		 */
		public int getId() {
			return id;
		}

		/**
		 * @param id the id to set
		 */
		public void setId(int id) {
			this.id = id;
		}

	/**
	 * @param saveFlag the saveFlag to set
	 */
	public void setSaveFlag(String saveFlag) {
		this.saveFlag = saveFlag;
	}

	
	
	
		/**
	 * @return the query_carnum
	 */
	public String getQuery_carnum() {
		return query_carnum;
	}

	/**
	 * @param query_carnum the query_carnum to set
	 */
	public void setQuery_carnum(String query_carnum) {
		this.query_carnum = query_carnum;
	}

	/**
	 * @return the rowsPerPage
	 */
	public int getRowsPerPage() {
		return rowsPerPage;
	}

	/**
	 * @param rowsPerPage the rowsPerPage to set
	 */
	public void setRowsPerPage(int rowsPerPage) {
		this.rowsPerPage = rowsPerPage;
	}

	/**
	 * @return the page
	 */
	public int getPage() {
		return page;
	}

	/**
	 * @param page the page to set
	 */
	public void setPage(int page) {
		this.page = page;
	}

	/**
	 * @return the totalPage
	 */
	public int getTotalPage() {
		return totalPage;
	}

	/**
	 * @param totalPage the totalPage to set
	 */
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	/**
	 * @return the planNum
	 */
	public int getPlanNum() {
		return planNum;
	}

	/**
	 * @param planNum the planNum to set
	 */
	public void setPlanNum(int planNum) {
		this.planNum = planNum;
	}

		/**
	 * @return the startdate
	 */
	public Date getStartdate() {
		return startdate;
	}

	/**
	 * @param startdate the startdate to set
	 */
	public void setStartdate(Date startdate) {
		this.startdate = startdate;
	}

		@Override
	    public String execute() throws Exception {
	        this.setSaveFlag("");
	        //维修车辆所属分公司
	        ActionContext actionContext = ActionContext.getContext();         
	        Map session = actionContext.getSession(); 
	        ZynUser loguser=(ZynUser) session.get("loginUser");    // the user session
	        this.carmt.setExtattr2(String.valueOf(loguser.getComId()));
	        
	        //所属分公司
			carDao.save(this.carmt);        //保存注册的car对象
			 this.setSaveFlag("保存成功..");
	        return SUCCESS;
	    }
		 public String findall() throws Exception {
		     
				this.setList(carDao.findCarQueryByPage(page, rowsPerPage,this.getQuery_carnum(),this.getStartdate()));       
		        this.setPlanNum(carDao.carTatolRows(this.getQuery_carnum(),this.getStartdate()).size());
		        this.setTotalPage(this.getPlanNum() % this.getRowsPerPage()==0?this.getPlanNum()/this.getRowsPerPage():this.getPlanNum()/this.getRowsPerPage()+1);     
			    return "success_list";
		
		    }
		 public String findbyid() throws Exception {
		        
			this.setCarmt(carDao.findById(this.getId()));// find the car by id			
		        return "s_find_one";
		       
		    }
		 public String edit() throws Exception {
		      			
			   carDao.merge(this.getCarmt());// edit the car by id			
			    return "s_edit_one";
			    }
		 public String delete() throws Exception {
		        
				carDao.delete(carDao.findById(this.getId()));// delete the car by id			
			    return "s_delete_one";
			    }
	}
